package com.jk.mapper;

import com.jk.entity.*;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface BalanceMapper {

    @Select("select * from i_balance where userid=#{userid}")
    @Results({
            @Result(property = "balanid", column = "balanid"),
            @Result(property = "userid", column = "userid"),
            @Result(property = "balance", column = "balance")

    })
    List<Balance> querybalance(Balance balance);

    /**
     * 查询用户基本信息
     * @param userinfo
     * @return
     */
    @Select("SELECT * from i_userinfo where registerid=#{registerid}")
    @Results({
            @Result(property = "userid", column = "userid"),
            @Result(property = "registerid", column = "registerid"),
            @Result(property = "username", column = "username"),
            @Result(property = "userphone", column = "userphone"),
            @Result(property = "balance", column = "balance"),
            @Result(property = "uservip", column = "uservip"),
            @Result(property = "lastyearintegral", column = "lastyearintegral"),
            @Result(property = "newyearintegral", column = "newyearintegral"),

    })
    List<Userinfo> queryuserinfo(Userinfo userinfo);

    @Select("SELECT * from i_userinfo  where userid=#{userid}")
    @Results({
            @Result(property = "registerid", column = "registerid"),
            @Result(property = "userid", column = "userid"),
            @Result(property = "username", column = "username"),
            @Result(property = "userphone", column = "userphone"),
            @Result(property = "balance", column = "balance"),
            @Result(property = "uservip", column = "uservip"),
            @Result(property = "lastyearintegral", column = "lastyearintegral"),
            @Result(property = "newyearintegral", column = "newyearintegral"),


    })
    Userinfo querycardinfo(String userinfo);

    /**
     * 根据用户名查询积分
     * @param userid
     * @return
     */
    @Select("SELECT bankcardnumber from i_bankinfo where userid=#{userid}")
    @Results({
            @Result(property = "bankcardid", column = "bankcardid"),
            @Result(property = "userid", column = "userid"),
            @Result(property = "bankcardtype", column = "bankcardtype"),
            @Result(property = "bankcardnumber", column = "bankcardnumber"),
            @Result(property = "bankcardphone", column = "bankcardphone")

    })
    List<BankInfo> querybankcardnumber(String userid);

    @Select("SELECT * from i_integral where userid=#{userid}")
    @Results({
            @Result(property = "integralid", column = "integralid"),
            @Result(property = "userid", column = "userid"),
            @Result(property = "uservip", column = "uservip"),
            @Result(property = "lastyearintegral", column = "lastyearintegral"),
            @Result(property = "newyearintegral", column = "newyearintegral")

    })
    Integral queryintegral(String userid);

    /**
     * 清空去年积分
     * @param integral
     * @return
     */
    @Update("UPDATE i_integral set lastyearintegral=newyearintegral,newyearintegral=0, uservip=#{uservip} WHERE userid=#{userid}")
    @Results({
            @Result(property = "integralid", column = "integralid"),
            @Result(property = "userid", column = "userid"),
            @Result(property = "uservip", column = "uservip"),
            @Result(property = "lastyearintegral", column = "lastyearintegral"),
            @Result(property = "newyearintegral", column = "newyearintegral")

    })
    void updateintegral(Integral integral);

    /**
     * 充值
     * @param recharge
     */
    @Update("UPDATE i_recharge set rechargenum=rechargenum+#{rechargenum} WHERE rechargeid=41")
    @Results({
            @Result(property = "rechargeid", column = "rechargeid"),
            @Result(property = "banknum", column = "banknum"),
            @Result(property = "idcard", column = "idcard"),
            @Result(property = "bankphone", column = "bankphone"),
            @Result(property = "bankname", column = "bankname"),
            @Result(property = "rechargenum", column = "rechargenum")


    })
    void saverecharge(Recharge recharge);

    @Insert("INSERT INTO i_bankinfo (bankcardid,bankcardtype,bankcardnumber) VALUES (#{bankcardid},#{bankcardtype},#{bankcardnumber})")
    @Results({
            @Result(property = "bankcardid", column = "bankcardid"),
            @Result(property = "userid", column = "cardid"),
            @Result(property = "bankcardtype", column = "bankcardtype"),
            @Result(property = "bankcardnumber", column = "bankcardnumber"),
            @Result(property = "bankcardphone", column = "bankcardphone"),

    })
    void addcard(BankInfo bankInfo);
    @Select("select count(*) from  i_userinfo  limit #{offset},#{limit} where registerid=#{registerid} ")
    long getuserinfosum(int i, int i1);
    @Select("select * from  i_userinfo  limit #{offset},#{limit} where registerid=#{registerid}")
    List<ShopCar> getuserinfolist(int i, int i1);
}
